package top.hzy520.dept.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.hzy520.dept.dao.DeptMapper;
import top.hzy520.dept.entity.Dept;

import java.util.List;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 16:02 2018/7/31
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> selectDeptList() {
        return deptMapper.selectDeptList();
    }

    @Override
    public Dept selectDeptById(Long deptId) {
        return deptMapper.selectByPrimaryKey(deptId);
    }

    @Override
    public boolean checkDeptNameUnique(Dept dept) {
    Dept  dbDept= deptMapper.selectDeptByName(dept.getName());
    if (dbDept==null){
        return true;
    }else {
        return false;
    }
    }

    @Override
    public void editDeptPost(Dept dept) {
        deptMapper.updateByPrimaryKeySelective(dept);
    }

    @Override
    public void addDeptPost(Dept dept) {
        deptMapper.insertSelective(dept);
    }

    @Override
    public void removeDeptPost(Long deptId) {
        deptMapper.deleteByPrimaryKey(deptId);
    }
}
